<template>
  <div style="margin: 0 5px;display: inline-block;">
    <el-button type="primary" size="mini" icon="el-icon-plus" round @click="ShowNewInclude">添加分类</el-button>
    <el-dialog title="添加分类" :visible.sync="is_show_include" :close-on-click-modal="false" width="30%" center>
      <el-form label-position="left" label-width="50px" :model="new_include" size="mini">
        <el-form-item label="名称">
          <el-input v-model="new_include.name" size="mini"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="is_show_include = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="SaveInclude" size="mini">添 加</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>

import axios from "axios";

export default {
  name: "CreateInclude",
  data() {
    return {
      is_show_include: false,
      new_include: {
        name: ""
      },
    }
  },
  methods: {
    ShowNewInclude() {
      this.new_include.name = ""
      this.is_show_include = true
    },
    SaveInclude() {
      axios({
        url: '/collector/includes/add',
        method: 'post',
        data: {
          name: this.new_include.name
        }
      }).then(({data}) => {
        if (data.code != 0) {
          this.$notify({
            title: '失败',
            message: data.msg,
            type: 'error'
          })
          return
        }
        window.location.reload()
      }).catch(err => {
        this.$notify({
          title: '失败',
          message: err.message,
          type: 'error'
        })
      })
      this.is_show_include = false
    },
  }
}
</script>